package com.hongye.house.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hongye.common.log.annotation.Log;
import com.hongye.common.log.enums.BusinessType;
import com.hongye.common.security.annotation.RequiresPermissions;
import com.hongye.house.domain.HouseResource;
import com.hongye.house.service.IHouseResourceService;
import com.hongye.common.core.web.controller.BaseController;
import com.hongye.common.core.web.domain.AjaxResult;
import com.hongye.common.core.utils.poi.ExcelUtil;
import com.hongye.common.core.web.page.TableDataInfo;

/**
 * 房源列表Controller
 * 
 * @author fafa
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/house")
public class HouseResourceController extends BaseController
{
    @Autowired
    private IHouseResourceService houseResourceService;

    /**
     * 查询房源列表列表
     */
    // @RequiresPermissions("house:house:list")
    @GetMapping("/list")
    public TableDataInfo list(HouseResource houseResource)
    {
        startPage();
        List<HouseResource> list = houseResourceService.selectHouseResourceList(houseResource);
        return getDataTable(list);
    }

    //  按排序方式  获取列表数据

    /****
     * @Author Ms.发发
     * @Description 排序方式  获取列表数据
     * @param sortType [综合排序,租金从高到低,租金从低到高]
     * @Date 2025/2/14 15:58
     * @return {@link TableDataInfo}
     */
/*
    @GetMapping("/listBySort/{sorType}")
    public TableDataInfo listBySort(@PathVariable("sortType") String sortType){
        startPage();
        List<HouseResource> list = houseResourceService.selectHouseResourceListBySort(sortType);
        return getDataTable(list);
    }
*/

    /**
     * 导出房源列表列表
     */
    @RequiresPermissions("house:house:export")
    @Log(title = "房源列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseResource houseResource)
    {
        List<HouseResource> list = houseResourceService.selectHouseResourceList(houseResource);
        ExcelUtil<HouseResource> util = new ExcelUtil<HouseResource>(HouseResource.class);
        util.exportExcel(response, list, "房源列表数据");
    }




    /**
     * 获取房源列表详细信息
     */
    @RequiresPermissions("house:house:query")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return success(houseResourceService.selectHouseResourceByHouseId(houseId));
    }


    /****
     * @Author Ms.发发
     * @Description 获取业主手机号
      * @param houseId  房源
     * @Date 2025/2/14 16:56
     * @return {@link AjaxResult}
     */
    @GetMapping( "getInfo/{houseId}")
    public AjaxResult getOwnerPhone(@PathVariable("houseId") Long houseId)
    {
        HouseResource houseResource = houseResourceService.selectHouseResourceByHouseId(houseId);
        return success(houseResource.getOwnerPhone());
    }



    /**
     * 新增房源列表
     */
    @RequiresPermissions("house:house:add")
    @Log(title = "房源列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HouseResource houseResource)
    {
        return toAjax(houseResourceService.insertHouseResource(houseResource));
    }

    /**
     * 修改房源列表
     */
    @RequiresPermissions("house:house:edit")
    @Log(title = "房源列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseResource houseResource)
    {
        return toAjax(houseResourceService.updateHouseResource(houseResource));
    }

    /**
     * 删除房源列表
     */
    @RequiresPermissions("house:house:remove")
    @Log(title = "房源列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(houseResourceService.deleteHouseResourceByHouseIds(houseIds));
    }
}
